import React from "react";
import CodeEditor from "@/components/CodeEditor";
import {Button, Modal} from "antd";

interface SqlModalProps {
    visible: boolean;
    onCancel: () => void;
    onSubmit: (sql: string) => void;
}

const SqlModal: React.FC = ({visible, onCancel, onSubmit} : SqlModalProps) => {
    const [sql, setSql] = React.useState('');

    const handleFinish = () => {
        onSubmit(sql);
    }

    return (
        <div>
            <Modal
                visible={visible}
                title="SQL"
                width={1500}
                onCancel={onCancel}
                footer={[
                    <Button key="cancel" onClick={onCancel}>
                        取消
                    </Button>,
                    <Button key="submit" type="primary" onClick={handleFinish}>
                        确认
                    </Button>,
                ]}
            >
                <CodeEditor value={sql} language="sql" height={650} onChange={(v) => {
                    setSql(v);
                }}/>
            </Modal>
        </div>
    )
}


export default SqlModal;